package com.lixin.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Pagination<T> {
    private Long currentPage; // 当前页
    private Long pageSize; // 每页记录数
    private Long pages; // 总页数
    private Long total; // 总记录数
    private T records;

    public static <T> Pagination<T> build(IPage<T> page) {
        Pagination<T> pagination = new Pagination<>();
        pagination.setCurrentPage(page.getCurrent());
        pagination.setPageSize(page.getSize());
        pagination.setPages(page.getPages());
        pagination.setTotal(page.getTotal());
        pagination.setRecords((T) page.getRecords());
        return pagination;
    }
}
